# -*- encoding: utf-8 -*-
"""
@Author: cuiyonghua
@CreateDate: 2021/6/2 下午3:07
@File: 切换窗口_关闭窗口句柄.py
@Description: 
"""
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait


def open_new_window(self, css, value):
    # 获得原始窗口句柄
    all_handles = self.driver.window_handles
    # 获得点击控件使用
    el = self.driver.find_element_by_class_name(value)
    el.click()

    # 判断新窗口打开
    WebDriverWait(self.driver, 10).until(EC.new_window_is_opened(all_handles))

    # 切换到原始串口
    self.driver.switch_to_window(self.driver.window_handles[0])

    # 切换到新打开窗口
    self.driver.switch_to_window(self.driver.window_handles[-1])
